package com.zzzzzz.core.web;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zzzzzz.account.signin.NoSuchOnlineUserException;
import com.zzzzzz.account.signin.OnlineService;
import com.zzzzzz.account.user.UserBase;

@Controller
public class GlobalController extends BaseController {

	@Resource
	private OnlineService onlineService;
	
	@RequestMapping(value = "/onusr", method = RequestMethod.GET)
    public @ResponseBody UserBase getCurrentUser() throws NoSuchOnlineUserException {
        UserBase userBase = onlineService.findUserBase();
        userBase.setId(userBase.getUserId().toString());
        return userBase;
    }
	
	@RequestMapping(value="/unauthorized", method=RequestMethod.GET)
	public String unauthorized(Model model, HttpServletRequest request) {
		if(onlineService.isSignedIn()) {
	        return "redirect:/home";
		}else {
	        return "redirect:/login";
		}
	}

	@RequestMapping(value = "/help", method = RequestMethod.GET)
	public String viewHelpPage(Model model) {
		return "help";
	}
	
	@RequestMapping(value = "/feedback", method = RequestMethod.GET)
	public String viewFeedbackPage(Model model) {
		return "feedback";
	}
	
}
